
'--------------------------------------------------
' Hands-On 7-1
'--------------------------------------------------

Sub ApplyBold()
    Do While ActiveCell.Value <> ""
        ActiveCell.Font.Bold = True
        ActiveCell.Offset(1, 0).Select
    Loop
End Sub



'--------------------------------------------------
' Hands-On 7-2
'--------------------------------------------------

Sub TenSeconds()
    Dim stopme

    stopme = Now + TimeValue("00:00:10")

    Do While Now < stopme
        Application.DisplayStatusBar = True
        Application.StatusBar = Now
    Loop

    Application.StatusBar = False
End Sub


Sub SignIn()
    Dim secretCode As String
    Do
        secretCode = InputBox("Enter your secret code:")
        If secretCode = "sp1045" Then Exit Do
    Loop While secretCode <> "sp1045"
End Sub


Sub ApplyBold2()
    Do Until IsEmpty(ActiveCell)
        ActiveCell.Font.Bold = True
        ActiveCell.Offset(1, 0).Select
    Loop
End Sub


'---------------------------------------------------
' Hands-On 7-3
'---------------------------------------------------

Sub DeleteBlankSheets()
    Dim myRange As Range
    Dim shcount As Integer
    shcount = Worksheets.Count
    Do
        Worksheets(shcount).Select
        Set myRange = ActiveSheet.UsedRange
        If myRange.Address = "$A$1" And _
            Range("A1").Value = "" Then
            Application.DisplayAlerts = False
            Worksheets(shcount).Delete
            Application.DisplayAlerts = True
        End If
        shcount = shcount - 1
    Loop Until shcount = 1
End Sub


'---------------------------------------------------
' Hands-On 7-4
' No Code in this Hands-On.
' Please follow the instructions in the book.
'---------------------------------------------------


'---------------------------------------------------
' Hands-On 7-5
'---------------------------------------------------

Sub ChangeRHeight()
    While ActiveCell <> ""
    ActiveCell.RowHeight = 28
    ActiveCell.Offset(1, 0).Select
    Wend
End Sub


'---------------------------------------------------
' Hands-On 7-6
'---------------------------------------------------

Sub DeleteZeroRows()
    Dim totalR As Integer
    Dim r As Integer
    
    Range("A1").CurrentRegion.Select
    totalR = Selection.Rows.Count
    Range("B2").Select
    
    For r = 1 To totalR - 1
        If ActiveCell = 0 Then
            Selection.EntireRow.Delete
            totalR = totalR - 1
        Else
            ActiveCell.Offset(1, 0).Select
        End If
    Next r
End Sub


'---------------------------------------------------
' Hands-On 7-7
'---------------------------------------------------

Sub RemoveSheets()
    Dim mySheet As Worksheet

    Application.DisplayAlerts = False

    Workbooks.Add
    Worksheets("Sheet2").Select

    For Each mySheet In Worksheets
        ActiveWindow.SelectedSheets.Delete
    Next mySheet

    Application.DisplayAlerts = True
End Sub


Sub IsSuchSheet()
    Dim mySheet As Worksheet
    Dim counter As Integer

    counter = 0

    For Each mySheet In Worksheets
        If mySheet.Name = "Sheet2" Then
            counter = counter + 1
        End If
    Next mySheet

    If counter = 1 Then
        MsgBox "This workbook contains Sheet2."
    Else
        MsgBox "Sheet2 was not found."
    End If
End Sub



'---------------------------------------------------
' Hands-On 7-8
'---------------------------------------------------


Sub EarlyExit()
    Dim myCell As Range
    For Each myCell In Range("A1:H10")
        If myCell.Value = "" Then
            myCell.Value = "empty"
        Else
            Exit For
        End If
    Next myCell
End Sub


'---------------------------------------------------
' Hands-On 7-9
'---------------------------------------------------

Sub ColorLoop()
    Dim myRow As Integer
    Dim myCol As Integer
    Dim myColor As Integer

    myColor = 0

    For myRow = 1 To 8
        For myCol = 1 To 7
            Cells(myRow, myCol).Select
            myColor = myColor + 1
            With Selection.Interior
                .ColorIndex = myColor
                .Pattern = xlSolid
            End With
        Next myCol
    Next myRow
End Sub






